package com.llongwill.slg.gateway;

import com.alibaba.nacos.api.PropertyKeyConst;
import com.xiangff.base.framework.encrypt.MD5Encoder;
import com.xiangff.base.framework.encrypt.XOREncoderAndDecoder;
import com.xiangff.base.framework.id.snowflake.Snowflake2IDGenerator;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.http.converter.HttpMessageConverter;

import java.util.stream.Collectors;

/**
 * 网关启动类
 *
 * @author xiangff
 */
@EnableFeignClients(basePackages = "com.llongwill")
@SpringBootApplication
@EnableDiscoveryClient
public class GatewayApplication {


    public static void main(String[] args) {
        System.setProperty(PropertyKeyConst.USERNAME,"nacos");
        System.setProperty(PropertyKeyConst.PASSWORD,"llw@qax213");
        SpringApplication.run(GatewayApplication.class, args);
    }

    @Bean
    @ConditionalOnMissingBean
    public HttpMessageConverters messageConverters(ObjectProvider<HttpMessageConverter<?>> converters) {
        return new HttpMessageConverters(converters.orderedStream().collect(Collectors.toList()));
    }

    @Bean
    public Snowflake2IDGenerator snowflake2IDGenerator() {
        return new Snowflake2IDGenerator();
    }

    @Bean
    public XOREncoderAndDecoder  xOREncoderAndDecoder(){
        return new XOREncoderAndDecoder("2llw#@!", true);
    }

    @Bean
    public MD5Encoder  mD5Encoder(){
        return new MD5Encoder();
    }
}
